//
//  NewFriendViewController.m
//  SunXi
//
//  Created by dllo on 15/12/3.
//  Copyright © 2015年 大远. All rights reserved.
//

#import "NewFriendViewController.h"

@interface NewFriendViewController ()<UITableViewDataSource,UITableViewDelegate,relodateDdelegate>
@property(nonatomic, strong) UITableView *tableView;
@end

@implementation NewFriendViewController


- (void)dealloc
{
    [[NSNotificationCenter defaultCenter]removeObserver:self name:@"收到添加" object:nil];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    SV.BC = [UIColor whiteColor];
    self.navigationItem.title = @"新的好友";
    self.navigationItem.rightBarButtonItem  = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(AddFriend)];
    [self.navigationItem.rightBarButtonItem setTintColor:BUTTONCOLOR];
    [self initTabelView];
      [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addmyFriend) name:@"收到添加" object:nil];
    
}
- (void)addmyFriend{
    if (self.tableView) {
        [self.tableView reloadData];
    }
}
- (void)initTabelView{
    self.tableView = ({
        UITableView *table = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) style:UITableViewStylePlain];
        table.delegate = self;
        table.dataSource = self;
        table.rowHeight = 100;
        table;
    });
    [SV addSubview:self.tableView];
}
- (void)AddFriend{
    //添加好友
    AddFriendViewController *NVC = [[AddFriendViewController alloc]init];
    [self.navigationController pushViewController:NVC animated:YES];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [UserModel shareSingleton].waitFriend.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    NewWithTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NewfriendCell"];
    if (!cell) {
        cell = [[NewWithTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"NewfriendCell"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.delegate = self;
    cell.number = indexPath.row;
    cell.model = [[UserModel shareSingleton].waitFriend objectAtIndex:indexPath.row];
    return cell;
}
- (void)removefriend:(NSInteger)number{
    [[UserModel shareSingleton].waitFriend removeObjectAtIndex:number];
    [self.tableView reloadData];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)presentLeftMenuViewController:(id)sender{
    [self.navigationController popViewControllerAnimated:YES];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
